package com.editso.haier.intercept;

import com.editso.haier.result.Result;
import com.editso.haier.result.ResultCode;
import org.apache.shiro.authz.UnauthenticatedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@ResponseBody
public class ExceptionIntercept {

    private Logger logger = LoggerFactory.getLogger(ExceptionIntercept.class);

    @ExceptionHandler(UnauthenticatedException.class)
    public Result unauthenticated(UnauthenticatedException e){
        return Result.result(ResultCode.NO_LOGIN);
    }

    @ExceptionHandler(Exception.class)
    public Result all(Exception e){
        logger.error("error",e);
        return Result.failure("失败");
    }
}
